package com.hd.controller.doc.article;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hd.controller.base.BaseController;
import com.hd.entity.doc.article.ArticleType;
import com.hd.service.doc.article.ArticleTypeService;
import com.hd.util.result.PageInfo;

/**
 * 文章类型
 */
@RequestMapping("articleType")
@Controller
public class ArticleTypeController extends BaseController {
    @Autowired
    private ArticleTypeService articleTypeService;

    /**
     * 主页
     *
     * @return
     */
    @RequestMapping("manager")
    public String manager() {
        return "jsp/doc/articleType/articleTypeList";
    }

    @RequestMapping(value = "/toTreeList")
    public String toTreeList() {
        return "jsp/doc/articleType/articleTypeTreeList";
    }

    @RequestMapping(value = "/toTreeSelect")
    public String toTreeSelect() {
        return "jsp/doc/articleType/articleTypeTreeSelect";
    }

    /**
     * 树
     *
     * @return
     */
    @RequestMapping(value = "/tree", method = RequestMethod.POST)
    @ResponseBody
    public Object tree(ArticleType articleType) {
        return articleTypeService.selectTree(articleType);
    }

    /**
     * 树列表
     *
     * @return
     */
    @RequestMapping("/treeGrid")
    @ResponseBody
    public Object treeGrid(ArticleType articleType) {
        return articleTypeService.selectTreeGrid(articleType);
    }

    /**
     * 列表
     *
     * @param page
     * @param rows
     * @param sort
     * @param order
     * @return
     */
    @RequestMapping(value = "/dataGrid", method = RequestMethod.POST)
    @ResponseBody
    public Object dataGrid(ArticleType articleType, Integer page, Integer rows, String sort, String order) {
        PageInfo pageInfo = new PageInfo(page, rows, sort, order);
        Map<String, Object> condition = new HashMap<String, Object>();
        pageInfo.setCondition(condition);
        articleTypeService.selectDataGrid(pageInfo);
        return pageInfo;
    }

    /**
     * 添加页
     *
     * @return
     */
    @RequestMapping("/addPage")
    public String addPage() {
        return "jsp/doc/articleType/articleTypeAdd";
    }

    /**
     * 添加
     *
     * @param articleType
     * @return
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    public Object add(ArticleType articleType) {
        articleTypeService.save(articleType);
        return renderSuccess("添加成功！");
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
    @ResponseBody
    public Object delete(@PathVariable("id") String id) {
        articleTypeService.delete(id);
        return renderSuccess("删除成功！");
    }

    /**
     * 编辑页
     *
     * @param model
     * @param id
     * @return
     */
    @RequestMapping("/editPage/{id}")
    public String editPage(Model model, @PathVariable("id") String id) {
        ArticleType articleType = articleTypeService.get(id);
        model.addAttribute("articleType", articleType);
        return "jsp/doc/articleType/articleTypeEdit";
    }

    @RequestMapping("/toSelect")
    public String toSelect(Model model, String ids, Boolean flag) {
        model.addAttribute("ids", ids);
        model.addAttribute("flag", flag);
        return "jsp/doc/articleType/articleTypeTreeSelect";
    }

    /**
     * 查看页
     *
     * @param model
     * @param id
     * @return
     */
    @RequestMapping("/viewPage/{id}")
    public String viewPage(Model model, @PathVariable("id") String id) {
        ArticleType articleType = articleTypeService.get(id);
        model.addAttribute("articleType", articleType);
        return "jsp/doc/articleType/articleTypeView";
    }

    /**
     * 编辑
     *
     * @param articleType
     * @return
     */
    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    @ResponseBody
    public Object edit(ArticleType articleType) {
        articleTypeService.update(articleType);
        return renderSuccess("编辑成功！");
    }


}
